package com.topscore.uke.mvp.model;

import com.topscore.uke.entities.MemberEntity;
import com.topscore.uke.mvp.contractors.GetMemberListContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/11/8.
 */

public class GetMemberListModel implements GetMemberListContractor.Model, GetMemberListContractor {
    private CallBack mCallBack;

    public GetMemberListModel(CallBack callBack) {
        this.mCallBack = callBack;
    }

    @Override
    public void getList(String userId,String role) {
        mService.getMemberList(userId,role)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<List<MemberEntity>>>(mCallBack) {
                    @Override
                    public void onSuccess(BaseResponse<List<MemberEntity>> response) {
                        mCallBack.onGetListSuccess(response.getData());
                    }
                });
    }
}
